package com.hnhs.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hnhs.exception.MyException;
import com.hnhs.info.PageInfo;
import com.hnhs.mapper.CategoryDao;
import com.hnhs.model.Category;
import com.hnhs.model.CategoryQuery;
import com.hnhs.utils.LocalpageInfoUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    public List<Category> select(CategoryQuery query){
       // int a=1/0;
//        if(query.getPageNum() != null && query.getPageSize() != null){
//            PageHelper.startPage(query.getPageNum(),query.getPageSize());
//        }

        List<Category> select = categoryDao.select(query);
//        if(select instanceof Page){
//            Page page= (Page) select;
//            long total = page.getTotal();
//            System.out.println(total);
//            LocalpageInfoUtil.set(PageInfo.builder().total(total).build());
//        }
//        if(1 == 1){
//            throw  new MyException(88,"报错了。。。");
//        }
        return select;
    }

    public int insert(Category category){
        return categoryDao.insert(category);
    }

    public int update(Category category){
       return categoryDao.update(category);
    }

    //软删除 逻辑删除 只改状态不删除数据
   public int delete(Integer id){
        return categoryDao.updateStatus(id,0);
   }



}
